chitu (Chuck Her In The Ute)
youtube.com/watch?v=9i2eZaJsC7g
JavaScript Utilities
Installation
via npm
> npm install chitu --save
via yarn
> yarn add chitu
Modules available
Chitu exports 3 module types:
import chitu from 'chitu'
import { type, round } from 'chitu'
const chitu = require('chitu')
window.chitu
Usage
type
A module to check the type of a given value.
import { type } from 'chitu'
type.isArray(['foo', 'bar'])
type.isObject({ foo: 'bar' })
type.isString('foo')
type.isDate(new Date())
type.isRegExp(/foo/g)
type.isFunction(function() {})
type.isBoolean(false)
type.isNumber(123)
type.isError(new Error())
type.isNull(null)
type.isUndefined(void 0)
type.is('Symbol', Symbol('foo'))
type.is('Map', new Map([]))
type.is('Set', new Set([]))
value
Check if the value is a function and execute it (with provided parameters) or simply return the
value.
import { value } from 'chitu'
const foo = (a, b, c) => a * b * c
const bar = ['baz']
const fooVal = value(foo, 2, 2, 2)
const barVal = value(bar)
round
Round a number to a given number of decimal places.
import { round } from 'chitu'
round(123.456)
round(1, 2)
round(1.937)
ordinal
Return the ordinal value for a given number.
import { ordinal } from 'chitu'
ordinal(1)
ordinal(2)
ordinal(3)
ordinal(4)
ordinal(12)
ordinal(101)
time
Return the human readable time string for a given number of seconds.
import { time } from 'chitu'
time(25)
time(100)
time(5000)
dot
Get an item from a given object using string dot notation.
import { dot } from 'chitu'
const obj = {
foo: {
bar: 'lorem',
baz: {
bob: true,
qux: null
}
}
}
dot(obj, 'foo.bar')
dot(obj, 'foo.baz.bob')
dot(obj, ['foo', 'baz', 'bob'])
dot(obj, 'foo.baz.bar', 'someDefault')
dot(obj, 'foo.foo.foo')
random
Generate a "random" alpha-numeric string.
import { random } from 'chitu'
random()
random(32)